package winter_vacation_homework.day_01;

import java.util.Scanner;

/**
 * 编写程序，对输入的年、月、日，给出该天是该年的第多少天？
 * 例如：2022年1月15日，是该年的第15天
 * 因为要考虑闰年问题，此处闰年采用简易算法
 */
public class Question2 {
    static int num = 0;

    public static void isDays(int year, int month, int day) {
        if (month >= 1 && month <= 2) {
            if (month == 1) {
                num = day;
                System.out.println(year + "年" + month + "月" + day + "日, " + "是该年的第" + num + "天");
            } else {
                num = 31 + day;
                System.out.println(year + "年" + month + "月" + day + "日, " + "是该年的第" + num + "天");
            }
        } else if (month >= 3 && month <= 12) {
            if (month % 2 == 0) {
                if (isLeapYear(year)) {
                    num = 30 * (month - 1) + day - 2 + month / 2;
                } else {
                    num = 30 * (month - 1) + day - 3 + month / 2;
                }
            } else {
                if (month >= 3 && month < 8) {
                    if (isLeapYear(year)) {
                        num = 30 * (month - 1) + day - 2 + (month - 1) / 2;
                    } else {
                        num = 30 * (month - 1) + day - 3 + (month - 1) / 2;
                    }
                } else {
                    if (isLeapYear(year)) {
                        num = 30 * (month - 1) + day - 2 + (month + 1) / 2;
                    } else {
                        num = 30 * (month - 1) + day - 3 + (month + 1) / 2;
                    }
                }
            }

        } else {
            System.out.println("The date entered is invalid");//翻译：输入日期不合法
        }
    }

    public static boolean isLeapYear(int year) {
        if (year % 400 == 0) {
            return true;
        }
        if (year % 4 == 0 && year % 100 != 0) {
            return true;
        } else {
            return false;
        }
    }

    public static void main(String[] args) {
        System.out.println("输入年月日");
        Scanner scanner = new Scanner(System.in);
        isDays(scanner.nextInt() , scanner.nextInt() , scanner.nextInt());
    }
}
